function [F1, F11, F2] = C57_CPP_Cross_Day_RM_DeltaT(XDay_RM_Summary)
%% get cross-day RM vs deltaT for C5

T1(:,1) = (extractfield(XDay_RM_Summary.C57_5, 'Date1'))';
T1(:,2) = (extractfield(XDay_RM_Summary.C57_5, 'Date2'))';
T1 = datetime(T1,'InputFormat','yyyy-MM-dd');

for n = 1:size(T1,1)
    deltaT1(n,1) = daysact(T1(n,1),T1(n,2));
end

RM1 (:,1) = extractfield(XDay_RM_Summary.C57_5, 'Memory_Index');

%% get cross-day RM vs deltaT for C6

T2(:,1) = (extractfield(XDay_RM_Summary.C57_6, 'Date1'))';
T2(:,2) = (extractfield(XDay_RM_Summary.C57_6, 'Date2'))';
T2 = datetime(T2,'InputFormat','yyyy-MM-dd');

for n = 1:size(T2,1)
    deltaT2(n,1) = daysact(T2(n,1),T2(n,2));
end

RM2 (:,1) = extractfield(XDay_RM_Summary.C57_6, 'Memory_Index');

%% get cross-day RM vs deltaT for C7

T3(:,1) = (extractfield(XDay_RM_Summary.C57_7, 'Date1'))';
T3(:,2) = (extractfield(XDay_RM_Summary.C57_7, 'Date2'))';
T3 = datetime(T3,'InputFormat','yyyy-MM-dd');

for n = 1:size(T3,1)
    deltaT3(n,1) = daysact(T3(n,1),T3(n,2));
end

RM3 (:,1) = extractfield(XDay_RM_Summary.C57_7, 'Memory_Index');

%% get cross-day RM vs deltaT for C8

T4(:,1) = (extractfield(XDay_RM_Summary.C57_8, 'Date1'))';
T4(:,2) = (extractfield(XDay_RM_Summary.C57_8, 'Date2'))';
T4 = datetime(T4,'InputFormat','yyyy-MM-dd');

for n = 1:size(T4,1)
    deltaT4(n,1) = daysact(T4(n,1),T4(n,2));
end

RM4 (:,1) = extractfield(XDay_RM_Summary.C57_8, 'Memory_Index');

%% linear regression

T_WT = cat(1,deltaT1,deltaT2,deltaT3,deltaT4);
RM_WT = cat(1,RM1,RM2,RM3,RM4);

figure
F1 = fit(T_WT,RM_WT,'poly1');
plot(F1,T_WT,RM_WT,'ob');
xlabel('deltaT (days)')
ylabel('mean(RM correlation)')
set(gca, 'FontSize', 20)
ylim([0,0.5])
xlim([0,53])
legend('off')
set(gca, 'Visible', 'off');

F11 = fitlm(T_WT,RM_WT);

%% AltRMnatively, exponential regression

figure
F2 = fit(T_WT,RM_WT,'exp1');
plot(F2,T_WT,RM_WT,'^b');
xlabel('deltaT (days)')
ylabel('mean(RM correlation)')
set(gca, 'FontSize', 20)
ylim([0,0.5])
xlim([0,53])
legend('off')
set(gca, 'Visible', 'off');


end